<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <base data-ice="baseUrl" href="../../">
  <title data-ice="title">Math3d/LineAndPoint.js | webpack-demo1</title>
  <link type="text/css" rel="stylesheet" href="css/style.css">
  <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
  <script src="script/prettify/prettify.js"></script>
  <script src="script/manual.js"></script>
</head>
<body class="layout-container" data-ice="rootContainer">

<header>
  <a href="./">Home</a>
  
  <a href="identifiers.html">Reference</a>
  <a href="source.html">Source</a>
  
  <div class="search-box">
  <span>
    <img src="./image/search.png">
    <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
  </span>
    <ul class="search-result"></ul>
  </div>
</header>

<nav class="navigation" data-ice="nav"><div>
  <ul>
    
  <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Circle.js~Circle.html">Circle</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/CircleAndPoint.js~CircleAndPoint.html">CircleAndPoint</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Common.js~Common.html">Common</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Line.js~Line.html">Line</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/LineAndCircle.js~LineAndCircle.html">LineAndCircle</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/LineAndPoint.js~PointAndLine.html">PointAndLine</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Point.js~Point.html">Point</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-EPSILON">EPSILON</a></span></span></li>
</ul>
</div>
</nav>

<div class="content" data-ice="content"><h1 data-ice="title">Math3d/LineAndPoint.js</h1>
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">export default  class PointAndLine {
  /**
   * &#x70B9;&#x5230;&#x76F4;&#x7EBF;&#x7684;&#x8DDD;&#x79BB;
   */
  static closestToSegment(point, a, b) {
    let ba = b.clone().sub(a);
    let t = point.clone().sub(a).dot(ba) / ba.lengthSq();
    return a.clone().lerp(b, Math.min(Math.max(t, 0), 1));
  }

  /**
   * &#x8BA1;&#x7B97;&#x70B9;&#x5728;&#x76F4;&#x7EBF;&#x7684;&#x6295;&#x5F71;&#x70B9;
   */
  static projection(point, lineStart, lineEnd) {
    let AM = new THREE.Vector3()
    let AB = new THREE.Vector3()
    AM.subVectors(point, lineStart)
    AB.subVectors(lineEnd, lineStart)
    const abLen2 = AB.dot(AB)
    const temp = AB.dot(AM)
    let scale = temp / abLen2
    return AB.multiplyScalar(scale).add(lineStart)
  }

  /**
   * &#x8BA1;&#x7B97;&#x70B9;&#x5728;&#x76F4;&#x7EBF;&#x7684;&#x955C;&#x50CF;
   */
  static reflection(point, lineStart, lineEnd) {
    let projPoint = Math3D.projection(point, lineStart, lineEnd)
    let newLine = new THREE.Vector3()
    newLine.subVectors(projPoint, point)
    return newLine.add(projPoint)
  }
}
</code></pre>

</div>

<footer class="footer">
  Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
</footer>

<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>
